package testBusiness;

import com.alibaba.fastjson.JSON;
import models.MyConfig;
import models.Request;
import models.ReturnJson;
import models.TestServerBusinessImpl;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by yangxianming on 2018/12/13.
 *
 */
public class TestScheduler implements TestServerBusinessImpl {
    @Override
    public String doIt(HttpServletRequest request, MyConfig myConfig) {
        ReturnJson returnJson = new ReturnJson();
        String requestInfo;
        try {
            requestInfo = Request.getBody(request);
            String printInfo = "";
            if (requestInfo.length() > 50){
                printInfo = requestInfo.substring(0, 50) + "...";
            }
            System.out.println(printInfo);
        }catch (Exception e){
            //请求流如果出现异常的时候
            returnJson.setApiStatus(0);
            returnJson.setErrorMsg(e.getMessage());
            return returnJson.toString();
        }
        myConfig.getNo1Factory().inputFactory(JSON.parseObject(requestInfo));

        return String.valueOf(myConfig.getNo1Factory().getListSize());
    }
}
